unit AcertaPrecoPromocao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBTables, Buttons;

type
  TFormAcertaPrecoPromocao = class(TForm)
    BitBtn1: TBitBtn;
    QueryPreco: TQuery;
    Label2: TLabel;
    EditPromocao: TEdit;
    QueryPrecoid: TIntegerField;
    QueryPrecovl_produto: TFloatField;
    QueryPrecovl_promocao: TFloatField;
    QueryAtualiza: TQuery;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure EditPromocaoKeyPress(Sender: TObject; var Key: Char);
    procedure EditPromocaoExit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormAcertaPrecoPromocao: TFormAcertaPrecoPromocao;

implementation

{$R *.dfm}

procedure TFormAcertaPrecoPromocao.BitBtn1Click(Sender: TObject);
var sql :string;
begin

    While not QueryPreco.Eof do
    begin

        sql := 'update prod_tamanho_produto set vl_promocao = '+EditPromocao.Text+' where id_produto = '+QueryPreco.FieldByName('id').AsString+' and id_tamanho = 0';
        QueryAtualiza.SQL.Clear;
        QueryAtualiza.SQL.Add(sql);
        QueryAtualiza.ExecSQL;

        

        QueryPreco.Next;
    end;

    close;    
end;

procedure TFormAcertaPrecoPromocao.FormShow(Sender: TObject);
begin
    QueryPreco.Open;


    EditPromocao.Text := formatfloat('###,###,##0.00', StrToFloat(QueryPreco.FieldByName('vl_promocao').AsString));
end;

procedure TFormAcertaPrecoPromocao.EditPromocaoKeyPress(Sender: TObject;
  var Key: Char);
begin
    if not(key in ['0'..'9','.',',',#8,#13]) then
       key := #0;

    if key in [',','.'] then
       key := DecimalSeparator;

   if Key = #13 then
   begin
      EditPromocao.Text := formatfloat('###,###,##0.00', StrToFloat(EditPromocao.Text));
      EditPromocao.SetFocus;
   end;
end;

procedure TFormAcertaPrecoPromocao.EditPromocaoExit(Sender: TObject);
begin
    EditPromocao.Text := formatfloat('###,###,##0.00', StrToFloat(EditPromocao.Text));
end;

end.
